package com.letme.web.controller.appletApi;

import com.letme.common.constant.Constants;
import com.letme.common.core.domain.AjaxResult;
import com.letme.framework.web.service.WxAppletLoginService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 微信登录类
 * @Description
 * @Author lock-xq
 * @Date 2025/9/11 16:52
 **/
@RestController
@Tag(name = "小程序-微信登录")
@RequestMapping("/auth")
public class WxLoginController {

    @Resource
    private WxAppletLoginService wxAppletLoginService;

    /**
     * 微信登录
     */
    @Operation(summary ="微信登录")
    @GetMapping("/wxLogin")
    public AjaxResult wxLogin(@RequestParam("code") String code, @RequestParam("deptId") Long deptId)
    {
        AjaxResult ajax = AjaxResult.success();
        // 生成令牌
        Object token = wxAppletLoginService.wxAppletLogin(code,deptId);
        ajax.put(Constants.TOKEN, token);
        return ajax;
    }


    /**
     * 微信手机号授权登录
     */
    @Operation(summary ="微信手机号授权登录")
    @GetMapping("/wxPhoneLogin")
    public AjaxResult wxPhoneLogin(@RequestParam("code") String code,
                                   @RequestParam("phoneCode") String phoneCode,
                                   @RequestParam("deptId") Long deptId)
    {
        AjaxResult ajax = AjaxResult.success();
        // 生成令牌
        String token = wxAppletLoginService.wxAppletPhoneLogin(code, phoneCode, deptId);
        ajax.put(Constants.TOKEN, token);
        return ajax;
    }
}
